package org.cangkuguanli.luoyuhang.controller;

import org.cangkuguanli.luoyuhang.bean.YuanGong;
import org.cangkuguanli.luoyuhang.mapper.GongyingshangMapper;
import org.cangkuguanli.luoyuhang.mapper.YuangongMapper;
import org.cangkuguanli.luoyuhang.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 登录接口
 */
@RestController
@RequestMapping("/yuangong")
public class YuangongController {


    @Autowired
    private YuangongMapper gongyingshangMapper;


    //用户登录
    @RequestMapping("/login")
    public JsonResult find(YuanGong user) { //参数
        System.out.println(user);
        YuanGong u = gongyingshangMapper.login(user);
        if (u == null) {
            // 登陆失败
            JsonResult result
                    = new JsonResult(false, 427, null, "登录 失败");
            return result;
        } else {
            // 登陆成功
            JsonResult result = new JsonResult(true, 200, u, "");
            return result;
        }
    }



    //用户注册
    @RequestMapping("/register")
    public JsonResult register(YuanGong user) { //参数
        gongyingshangMapper.add(user);
        JsonResult result = new JsonResult(true,200,"success","");
        return result;
    }
}
